/*
*  城市级联选择控件
*  @placeholderText {String} 控件提示
*  @options {Array} 选项数组
*  @pickAreaHandler {Func} 选择数据事件
*  @hasAreaFlag {Boolean} 是否选择到区，镇
* */

import React, {Component} from 'react';
import { Cascader } from 'antd';
import options from './areaPickerOption';
import PropTypes from 'prop-types';

class AreaPicker extends Component {
  constructor (props) {
    super();
    this.props = props;
    this.hasAreaFlag = !1;
    this.placeholderText = '请选择地址';
    this.options = null;
  }

  componentWillMount () {
    this.pickAreaHandler = this.props.pickAreaHandler;
    this.options || (this.options = options(this.hasAreaFlag));
  }

  render () {
    const renderDom = <Cascader options={this.options} onChange={this.pickAreaHandler} placeholder={this.placeholderText} />;
    return renderDom;
  }
}

export default AreaPicker;

AreaPicker.propTypes = {
  pickAreaHandler: PropTypes.func
}